package com.flute.icrawler.check.util;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.flute.icrawler.check.formxml.CrawlerCheckSerivce;

public class Util {
	private static String rootDir = "";
	private static final Logger logger = LoggerFactory.getLogger(CrawlerCheckSerivce.class);
	static List<Map<String, Long>> list = new ArrayList<Map<String, Long>>();
	static Map<String, Long> map = new HashMap<String, Long>();
	
	public static Map<String, Long> getRateMap(){
		return map;
	}
	
	
	public static String getRootDir(String directoryName) {
		rootDir =  "./"  + directoryName;
		checkDir(rootDir);
		return rootDir;
	}
	public static void checkDir(String rootDir){
		try{
			File file = new File(rootDir);
			if(!file.exists()){
				file.mkdir();
				logger.info("创建文件夹" + rootDir);
			}
		}catch(Exception e){
			logger.error("创建文件夹失败",e);
		}
		
	}
	//不考虑元素顺序是否相同   
	public static boolean isSame(List<?> a,List<?> b){   
	        if(a.size() != b.size()){   
	            return false; 
	        }   
	       for(Object tem : a){   
	            if(!b.contains(tem)){
	                return false;   
	           }   
	       }   
	        return true;   
	    }  
	/**
     * 正则表达式查找字符串
     * @param strMould
     * @return
     */
    public static String findTargetInStr(String strMould, String text) {
        String reStr = "";
        Pattern pattern = Pattern.compile(strMould);
        Matcher matcher = pattern.matcher(text);

        if (matcher.find()) {
            reStr = matcher.group(1);
        }

        return reStr;
    }
    @SuppressWarnings("unchecked")
	public static void saveUpateRate(String id,long l){
    	map.put(id + "|" + l, l);
    }



}
